package com.bds.tjj.action;

import com.bds.tjj.model.*;
import com.bds.tjj.model.common.Result;
import com.bds.tjj.service.*;
import com.bds.tjj.utils.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by guoyu on 2018/3/2.
 */
@RestController
public class TabDetailController {
    @Autowired
    private YearSumService yearSumService;
    @Autowired
    private MonthSumService monthSumService;
    @Autowired
    private UserService userService;
    @Autowired
    private QuarterSumService quarterSumService;

    @RequestMapping(value = "/service/data/get_tab_detail/{area_id}", method = RequestMethod.GET)
    public Result getTabDetails(@PathVariable String area_id) {
        Result result = new Result();
        List<TabDetail> resultList = new ArrayList<>();
        try {
            List<String> list = userService.getTabNames();
            for (String tabName : list) {
                List<YearData> ys = yearSumService.getYearTips(tabName);
                List<MonthData> ms = monthSumService.getMonthTips(tabName);
                List<QuarterData> qs = quarterSumService.getQuarTips(tabName);
                List<QuarterAreaData> qad = quarterSumService.getQuarAreaTips(tabName, area_id);
                List<YearAreaData> yad = yearSumService.getYearAreaTips(tabName, area_id);

                TabDetail tabDetail = new TabDetail();
                tabDetail.setTabName(tabName);
                tabDetail.setMonthDataList(ms);
                tabDetail.setYearDataList(ys);
                tabDetail.setQuarterDataList(qs);
                tabDetail.setQuarterAreaDataList(qad);
                tabDetail.setYearAreaDataList(yad);

                resultList.add(tabDetail);
            }

            result.setResult(Const.SUC, resultList);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            result.setResult(Const.FAIL, null);
        }

        return result;
    }
}
